# Maintainer: George Rawlinson <george@rawlinson.net.nz>
# Contributor: Arthur Darcet <arthur.darcet at m4x.org>
# Contributor: Techlive Zheng <techlivezheng at gmail.com>

pkgname=libiconv
pkgver=1.17
pkgrel=1
pkgdesc='GNU charset conversion library'
arch=('loong64' 'x86_64')
url='http://www.gnu.org/software/libiconv/'
license=('LGPL')
depends=('glibc')
source=("https://ftp.gnu.org/pub/gnu/$pkgname/$pkgname-$pkgver.tar.gz"{,.sig})
options=(!libtool)
validpgpkeys=('9001B85AF9E1B83DF1BDA942F5BE8B267C6A406D') # Bruno Haible <bruno@clisp.org>
sha512sums=('18a09de2d026da4f2d8b858517b0f26d853b21179cf4fa9a41070b2d140030ad9525637dc4f34fc7f27abca8acdc84c6751dfb1d426e78bf92af4040603ced86'
            'SKIP')
b2sums=('1d317dd0655c680a2082c38561cdff51ac1a9181d4734a8bb1e86861dfd66f1a6c0846a90b5b88f3b38b1fa9983d9e563551f27e95a8e329896b71becceae52b'
        'SKIP')

build() {
  cd "$pkgname-$pkgver"

  ./configure \
    --prefix=/usr \
    --docdir=/usr/share/doc/libiconv \
    --enable-extra-encodings

  # workaround for insecure rpath
  sed -i 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' libtool
  sed -i 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' libtool

  make
}

package() {
  cd "$pkgname-$pkgver"

  make DESTDIR="$pkgdir" install

  # move references from iconv to libiconv
  mv -v "$pkgdir"/usr/include/{iconv.h,libiconv.h}
  mv -v "$pkgdir"/usr/bin/{iconv,libiconv}
  mv -v "$pkgdir"/usr/share/man/man1/{,lib}iconv.1
  mv -v "$pkgdir"/usr/share/man/man3/{,libiconv_}iconv.3
  mv -v "$pkgdir"/usr/share/man/man3/{,libiconv_}iconvctl.3
  mv -v "$pkgdir"/usr/share/man/man3/{,libiconv_}iconv_open.3
  mv -v "$pkgdir"/usr/share/man/man3/{,libiconv_}iconv_close.3
  mv -v "$pkgdir"/usr/share/man/man3/{,libiconv_}iconv_open_into.3
}
